define([
    "underscore",
    'backbone',
    "common",
    'routes'
], function (_, Backbone, common, routes) {
    'use strict';
    window.console.log("routes:" + JSON.stringify(routes));
    var AppRouter = Backbone.Router.extend({
        routes: function () {
            var obj = {
                '': "toDefault",
                '*Page': "toPage",
                '*Page/:url': "toPage",
                '*error': "toError"
            };
            return $.extend({}, routes.pathSetAction(), obj);
        },
        toDefault: function () {
            common.goto("topPage", false);
        },
        // toPage: function () {
        //     routes.action();
        // },
        toError: function (error) {
            console.log('URL错误, 错误信息: ' + JSON.stringify(arguments));
            common.popup.show({
                type: "B",
                content: 'URL错误, 错误信息: ' + JSON.stringify(arguments),
                yes: "关闭",
                callback: function () {
                    common.goto(routes.current);
                },
            });
        }
    });

    var appRouter = new AppRouter();
    routes.pathSetEvent(appRouter);
    window.console.log("appRouter:" + JSON.stringify(appRouter));
    return appRouter;
});